package flowlight.webApp;

import flowlight.entity.Scennic;
import flowlight.entity.scennicPic;
import flowlight.service.ScenicPicService;
import flowlight.service.ScennicService;
import flowlight.utils.JsonVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("flowlight")
public class Login {

    @Resource(name = "ScennicService")
    private ScennicService scennicService;

    @Resource(name = "ScenicPicService")
    private ScenicPicService scenicPicService;

    @RequestMapping("login.htm")
    public String login() {
        return "flow/login";
    }

    @RequestMapping("index.htm")
    public String main() {
        return "flow/index";
    }

    @RequestMapping("jingdian.htm")
    public String article(Model model) {
        List<Scennic> scennicList = scennicService.selectAllScennic();
        model.addAttribute("ScennicList",scennicList);
        return "flow/mypage/jingdianlist";
    }

    @RequestMapping("addjingdian.htm")
    public String addJingDain() {
        return "flow/mypage/addjingdain";
    }

    @RequestMapping("addjingdianPic.htm")
    public String getaddjingdianPic(Model model,int scennicId) {
        List<scennicPic> scennicPics = scenicPicService.selectAllPic(scennicId);
        model.addAttribute("scennicPics",scennicPics);
        model.addAttribute("scennicId",scennicId);
        return "flow/mypage/imgList";
    }

    @RequestMapping("addjingdianPic")
    @ResponseBody
    public JsonVo<String> addJingDianPic(scennicPic scennicPic) {
        JsonVo<String> jsonVo = new JsonVo<String>();
        scenicPicService.insertSelective(scennicPic);
        jsonVo.setCode(200);
        jsonVo.setMsg("添加成功");
        return jsonVo;
    }

}
